﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Text;
namespace Pakxel.SmartLogistic
{
    static class MainApp
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
       
       static System.IO.StreamWriter logger = new System.IO.StreamWriter(System.Environment.CurrentDirectory + "\\log.txt",false);
       static WorkBench wb;

       public static WorkBench Wb
       {
           get { return MainApp.wb; }
       }


       public static void WriteToLog(string msg)
       {
        logger.WriteLine("{0} - {1}",DateTime.Now, msg);
        logger.Flush();
       }

       public static void WriteExceptionToLog(Exception e)
       {
          logger.WriteLine("{0} - Exception : {1} \n TargetSite : {2} \n Message : {3} \n Stack : {4}", DateTime.Now,e.ToString(), e.TargetSite ,e.Message,e.StackTrace);
          if (e.InnerException != null)
          {
             WriteExceptionToLog(e.InnerException);
             logger.Flush();
          }
       }

       [STAThread]

       static void Main()
           {
           
            logger.AutoFlush = true;
            //logger.FormatProvider =
            System.Console.SetOut(logger); 
            AppDomain.CurrentDomain.SetupInformation.ConfigurationFile = @"C:\AppSettings.xml";  
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new WorkBench());
            wb = new WorkBench();
            Application.Run(wb);
            logger.Close();
           }
    }
}
